// set path 
gl path "~/"

use g_ homeowner_g id year birth_year reg_year using "$path/Replication/ohio_analysis_local.dta" if birth_year <= 1960 & birth_year > 1930, clear

// keep if registered before treatment
keep if reg_year < year
drop reg_year

// rename and label homeowner variable
estimates clear
gen homeowner = homeowner_g
label variable homeowner "Homeowner"
drop homeowner_g
compress

// drop if missing
drop if g_ == .
drop if homeowner == .

eststo: reghdfe g_ homeowner, a(id year) cluster(id)
	sum g_ if e(sample)	
	estadd scalar avg = r(mean)
drop _est*

use "$path/Replication/exact_matched_over_40.dta", clear
*** get weights for fw based on total n per stratum
*** each stratum has 18 obs
*** fw requires integers so need to round
gen tot2 = round(tot/18)
label variable homeowner "Homeowner"
// generate outcome path fixed effect
egen op = group(outcome_path)
eststo: reghdfe g_ homeowner [fw=tot2], a(op year)
	sum g_ [aw=tot] if e(sample)
	estadd scalar avg = r(mean)
	
use g_ homeowner_g id year birth_year reg_year using "$path/Replication/ohio_analysis_local.dta" if birth_year != ., clear

// keep if registered before treatment
keep if reg_year < year
drop reg_year

// rename and label homeowner variable 
gen homeowner = homeowner_g
label variable homeowner "Homeowner"
drop homeowner_g
compress

// drop if missing
drop if g_ == .
drop if homeowner == .

eststo: reghdfe g_ homeowner, a(id birth_year#year) cluster(id)
	sum g_ if e(sample)	
	estadd scalar avg = r(mean)
drop _est*
	
use g_ homeowner_g property id year reg_year using "$path/Replication/ohio_analysis_local.dta", clear

// keep if registered before treatment
keep if reg_year < year
drop reg_year

// rename and label homeowner variables
gen homeowner = homeowner_g
label variable homeowner "Homeowner"
drop homeowner_g
gen homeowner_sfr = homeowner * (property == 10)
label variable homeowner_sfr "Homeowner * Single Family Residence"

drop property

compress

// drop if missing
drop if g_ == .
drop if homeowner == .

eststo: reghdfe g_ homeowner homeowner_sfr, a(id year) cluster(id)
	sum g_ if e(sample)	
	estadd scalar avg = r(mean)
drop _est*

// export coefficients to tex file
esttab using "$path/Replication/Table2.tex", ///
substitute(\hline "\midrule" [1em] "" "avg" "Outcome Mean") tex ///
nostar  label  replace nonotes nomtitles nonumbers fragment scalar(N avg)  ///
b(%8.3f) se(%8.3f) sfmt(%12.0fc %4.3f) nolines varlabels( , elist(homeowner \addlinespace)) ///
compress

